﻿using Report_IService.Web;
using Report_Model.Web;
using Report_Service.Web;
using Report_Unity.Basic;
using Report_Unity.Log;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace ReportWebApi.Controllers.Api.WeiXin
{
    [RoutePrefix("api/User")]
    public class UserController : BaseApiController
    {
        private IT_UserService T_UserService = new T_UserService();

        [HttpGet, Route("GetLoginTicket")]
        public ResultInfo GetLoginTicket(string hid)
        {
            ResultInfo res = T_UserService.GetLoginTicket(hid);
            return res;
        }

        [HttpPost, Route("RegOrLoginWithCode")]
        public ResultInfo RegOrLoginWithCode()
        {
            var req = HttpContext.Current.Request;
            string hid = req.Form["hid"];
            string phone = req.Form["phone"];
            string code = req.Form["code"];
            string ipaddr = req.Form["ipaddr"];

            ResultInfo res = T_UserService.RegOrLoginWithCode(hid, phone, code, ipaddr);
            return res;
        }

        [HttpPost, Route("Login")]
        public ResultInfo Login()
        {
            var req = HttpContext.Current.Request;
            string hid = req.Form["hid"];
            string phone = req.Form["phone"];
            string pwd = req.Form["pwd"];
            string ipaddr = req.Form["ipaddr"];
            string ticket = req.Form["ticket"];
            string code = req.Form["code"];
            ResultInfo res = T_UserService.Login(hid, phone, pwd, ipaddr, ticket,code);
            return res;
        }

        [HttpGet, Route("GetPersonalInfo")]
        public ResultInfo GetPersonalInfo(string userid, string hid)
        {
            ResultInfo res = T_UserService.GetPersonalInfo(userid, hid);
            return res;
        }

        [HttpGet, Route("GetUser")]
        public ResultInfo GetUser(string userid, string hid)
        {
            ResultInfo res = T_UserService.GetUser(userid, hid);
            return res;
        }

        [HttpPost, Route("SendCode")]
        public ResultInfo SendCode()
        {
            var req = HttpContext.Current.Request;
            string userid = req.Form["userid"];
            string hid = req.Form["hid"];
            string phone = req.Form["phone"];

            ResultInfo res = T_UserService.SendCode(userid, hid, phone);
            return res;
        }

        [HttpPost, Route("EditPhone")]
        public ResultInfo EditPhone()
        {
            var req = HttpContext.Current.Request;
            string userid = req.Form["userid"];
            string hid = req.Form["hid"];
            string phone = req.Form["phone"];
            string code = req.Form["code"];

            ResultInfo res = T_UserService.EditPhone(userid, hid, phone, code);
            return res;
        }

        [HttpPost, Route("EditUser")]
        public ResultInfo EditUser()
        {
            var req = HttpContext.Current.Request;
            string name = req.Form["name"];
            string idcard = req.Form["idcard"];
            string sex = req.Form["sex"];
            string birthday = req.Form["birthday"];
            string hid = req.Form["hid"];
            string userid = req.Form["userid"];

            ResultInfo res = T_UserService.EditUser(userid, hid, idcard, sex, birthday, name);
            return res;
        }
    }
}
